# db connection

import MySQLdb

HOST = "localhost"
USER = "root"
PWD = "123456"
DB = "sakila"

connection = None

def connectToDb():
    print "Connecting to: " + HOST + ", db: " + DB
    global connection
    connection = MySQLdb.connect(host="localhost", user="root", passwd="123456", db="sakila")
    print connection
    
def disconnectFromDb():
    print "Disconnecting from : " + HOST + ", db: " + DB
    global connection
    print connection
    connection.close()

def executeStmt(stmt):
    cursor = connection.cursor()
    print "Executing: " + stmt
    rows = []
    try:
        cursor.execute(stmt)
        rows = cursor.fetchall()
    except MySQLdb.ProgrammingError:
        print "There is an error in the SQL syntax."
    return rows



